class Linklist:#链表类
    class Node:#节点
        def __init__(self,item=None):
            self.item=item
            self.next=None
    class LinkListIterator:
        def __init__(self,node):
            self.node=node
        def __next__(self):
            if self.node:
                curNode=self.node
                self.node=curNode.next
                return curNode.item
            else:
                raise StopIteration
        
        def __iter__(self):
            return self
    def __init__(self,iterable=None):#传一个链表进来
        self.head=None#头
        self.tail=None#尾
        if iterable:
            self.extend(iterable)
    def append(self,obj):#从尾插入
        s=Linklist.Node(obj)#创造一个链表节点
        if not self.head:
            self.head=s
            self.tail=s
        else:
            self.tail.next=s
            self.tail=s
    def extend(self,iterable):#创建链表
        for obj in iterable:
            self.append(obj)
    def find(self,obj):
        for n in self:
            if n==obj:
                return True
    def __iter__(self):
        return self.LinkListIterator(self.head)
    def __repr__(self) :#打印
        return "<<"+",".join(map(str,self))+">>"#map:将可迭代每一个元素转换为字符串
# 类似于集合的结构
class HashTable:
    def __init__(self,size=101) :
        self.size=size
        self.T=[Linklist() for i in range(self.size)]
    def h(self,k):#哈希函数
        return k % self.size
    def find(self,k):
        i=self.h(k)#查找哈希值
        return self.T[i].find(k)
    def insert(self,k):
        i=self.h(k)
        if self.find(k):
            print("Duplicated Insert")
        else:
            self.T[i].append(k)
            return self.T[i].find(k)
    def print_H(self):#打印
        print(".".join(map(str,self.T)))
if __name__=="__main__":
    lk=Linklist([1,2,3,4,5])
    print(lk)
    ht=HashTable()
    ht.insert(0)
    ht.insert(1)
    ht.insert(3)
    ht.insert(102)
    ht.insert(508)
    #ht.print_H()
    print(ht.find(102))


